import './index.scss';
import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
export default {
  data () {
    return {
      pageNoGk: 1,
      pageNoNd: 1,
      pageSize: 5,
      list: [],
      listGk: '',
      listNd: '',
      witchOne: 'xinxi',
      tishi: '',
      isA: true
    }
  },
  mounted () {
    if (this.$emit('ifOpenid')) {
      this.$emit('ifOpenid', this.$route.path)
    }
    this.xinxi()
  },
  methods: {
    tabChange (e) {
      this.tishi = ''
      if (e == 'xinxi') {
        this.witchOne = 'xinxi'
        this.isA = true
        this.list = this.listGk
      } else {
        this.witchOne = 'niandu'
        this.isA = false
        if (this.listNd == '') {
          this.niandu()
        } else {
          this.list = this.listNd
        }

      }
    },
    xinxi () {
      http.post(CONSTANT.INFO_PUBLIC, {info_type: 1, pageNo:this.pageNoGk, pageSize:this.pageSize}, (res) => {
        if (res.code == 200) {
          console.log(res)
          if (res.errmsg == '没有更多的信息') {
            this.pageNoGk--
            this.tishi = '———— 没有更多了 ————'
            return
          }
          this.listGk = res.list
          this.list = this.listGk
        } else {
          console.log('出错了！')
        }
      })
    },
    niandu () {
      http.post(CONSTANT.INFO_PUBLIC, {info_type: 2, pageNo:this.pageNoNd, pageSize:this.pageSize}, (res) => {
        if (res.code == 200) {
          if (res.errmsg == '没有更多的信息') {
            this.pageNoNd--
            this.tishi = '———— 没有更多了 ————'
            return
          }
          this.listNd = res.list
          this.list = this.listNd
        } else {
          console.log('出错了！')
        }
      })
    },
    lastPage () {
      this.tishi = ''
      if (this.witchOne == 'xinxi') {
        this.pageNoGk--
        if (this.pageNoGk <= 0) {
          this.pageNoGk++
          this.tishi = '———— 已经是第一页了 ————'
          return
        }
        this.xinxi()
      } else {
        this.pageNoNd--
        if (this.pageNoNd <= 0) {
          this.pageNoNd++
          this.tishi = '———— 已经是第一页了 ————'
          return
        }
        this.niandu()
      }
    },
    nextPage () {
      this.tishi = ''
      if (this.witchOne == 'xinxi') {
        this.pageNoGk++
        this.xinxi()
      } else {
        this.pageNoNd++
        this.niandu()
      }
    },
    goDetails (e) {
      console.log(e)
      this.$router.push({path: '/findmessageDetails', query: {id: e}})
    },
    comeBack () {
      window.history.back()
    }
  }
}
